package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.User;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class UserDao {

	DBHelp<User> db = new DBHelp<User>();
	
	public User findByName(String username) {
		String sql = "select id,username,password from t_user where username = ?";
		return db.executeQueryForObject(sql, new UserRowMapper(),username);
	}

	public class UserRowMapper implements RowMapper<User>{

		public User mapperRow(ResultSet rs) throws SQLException {
			User u = new User();
			u.setUserid(rs.getInt("userid"));
			u.setUsername(rs.getNString("username"));
			u.setPassword(rs.getNString("password"));
			return u;
		}
		
	}
}
